<!DOCTYPE html>
<html lang="en" dir="ltr">

<head>
  <meta charset="UTF-8">
  <title>Button - Dynamic</title>
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
  <link href="../../../../../css/ionic.bundle.css" rel="stylesheet">
  <link href="../../../../../scripts/testing/styles.css" rel="stylesheet">
  <script src="../../../../../scripts/testing/scripts.js"></script>
  <script nomodule src="../../../../../dist/ionic/ionic.js"></script>
  <script type="module" src="../../../../../dist/ionic/ionic.esm.js"></script></head>
</head>

<body>
  <ion-app>

    <ion-header>
      <ion-toolbar>
        <ion-title>Button - Dynamic</ion-title>
      </ion-toolbar>
    </ion-header>

    <ion-content class="ion-padding" id="content" no-bounce>
      <ion-item id="dynamicItem">
        <ion-button slot="start">Default</ion-button>
        <ion-label>Dynamic Button</ion-label>
        <ion-button id="dynamicItemLarge" slot="end" size="large">Large</ion-button>
      </ion-item>
      <ion-button id="add-item-button" color="success" onClick="addButton('dynamicItem')">
        Add a Button
      </ion-button>
      <ion-button id="change-item-button" color="tertiary" onClick="changeButtonSize('dynamicItemLarge')">
        Change Button Size
      </ion-button>

      <ion-item-divider id="dynamicItemDivider">
        <ion-button slot="start">Default</ion-button>
        <ion-label>Dynamic Button</ion-label>
        <ion-button id="dynamicItemDividerLarge" slot="end" size="large">Large</ion-button>
      </ion-item-divider>
      <ion-button id="add-item-divider-button" color="success" onClick="addButton('dynamicItemDivider')">
        Add a Button
      </ion-button>
      <ion-button id="change-item-divider-button" color="tertiary" onClick="changeButtonSize('dynamicItemDividerLarge')">
        Change Button Size
      </ion-button>
    </ion-content>

  </ion-app>

  <script>
    function addButton(dynamicId) {
      var item = document.querySelector('#' + dynamicId);
      var button = document.createElement("ion-button");
      button.textContent = "Button";
      button.slot = "start";
      item.appendChild(button);
    }

    function changeButtonSize(dynamicId) {
      var button = document.querySelector('#' + dynamicId);
      var size = button.size === 'large' ? undefined : 'large';
      button.size = size;
    }
  </script>
</body>

</html>
